﻿@model Von.Web.Structs.HtmlCatalogInfo
@{
    ViewData["Title"] = "产品分类管理";
}
<div id="QueryCriterion" class="row">
    <div class="col-md-1 col-condition"><input type="text" data-level="1" data-connector="OR" data-field="HtmlName" data-condition="前后近似" class="form-condition" placeholder="文档名称" /></div>
    <div class="col-md-1 col-condition"><input type="text" data-level="1" data-connector="OR" data-field="Tags" data-condition="后近似" class="form-condition" placeholder="标签" /></div>
    <div class="col-md-1 col-condition"><input type="text" data-level="1" data-connector="OR" data-field="Keyword" data-condition="前后近似" class="form-condition" placeholder="关键词" /></div>
    <div class="col-md-1 col-condition"><input type="text" data-level="1" data-connector="OR" data-field="Autor" data-condition="后近似" class="form-condition" placeholder="作者" /></div>
    <div class="col-md-1 col-condition"><input type="datetime-local" data-level="0" data-field="CreateTime" data-condition="大于" class="form-condition" placeholder="起始发布时间" value="@DateTime.Now.AddMonths(-1).ToString(" yyyy-MM-dd")" /></div>
    <div class="col-md-1 col-condition"><input type="datetime-local" data-level="0" data-field="CreateTime" data-condition="小于" class="form-condition" placeholder="结束发布时间" value="@DateTime.Now.AddDays(1).ToString(" yyyy-MM-dd")" /></div>
    <div class="col-md-1"><input tyle="button" class="btn btn-primary" value="查询" onclick="search(this)" /></div>
</div>
<div class="row">
    <div class="col-md-2" style="width:171px">
        <div><span id="Addinfo">请选择文档分类</span></div>
        <table id="catalogTree" title="文档分类" class="easyui-tree"></table>
    </div>
    <div class="col-md-10">
        <div id="ContentListTitle" class="page-header" hidden><h3><span id="title"></span><small><a id="btnAdd" onclick="EditContent(this)" class="btn btn-link">添加新文档</a></small></h3></div>
        <table class="table" id="ContentList">
            <caption></caption>
            <thead>
                <tr>
                    <th>文档名称</th>
                    <th>标题</th>
                    <th>作者</th>
                    <th>来源</th>
                    <th>状态</th>
                    <th>发布时间</th>
                    <th></th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    var PRoNode = "";
    function search(btn) {
        var data = [];
        $("#QueryCriterion [data-field]").each(function () {
            if ($(this).val() != '') {
                var queryItem = { FieldName: $(this).attr("data-field"), Condition: $(this).attr("data-condition"), Data: $(this).val() };
                queryItem.Level = $(this).attr("data-level") == undefined ? 0 : $(this).attr("data-level");
                queryItem.Connector = $(this).attr("data-connector") == undefined ? "AND" : $(this).attr("data-connector");
                data.push(queryItem);
            }
        });
        AjaxPostData('@Url.Ajax("SearchHtmlContent")', data, function (result) {
            von.clearTable();
            for (idx in result) von.appendRow(von.getHtml(result[idx]));
        });
    }
    function LoadContentList(node) {
        if (node != null && node != undefined) {
            PRoNode = node;
            $("#ContentListTitle").show();
            $("#catalogText").val(node.text);
            $("#ContentListTitle span").text(node.text + " 文档列表");
            $("#CatalogIdx").val(node.id);
            AjaxPostData('@Url.Ajax("ListHtmlContent")', { CatalogIdx: node.id }, function (datas) {
                von.clearTable();
                von.appendTable(datas);
            });
        }
    }
    function getCurrentNode() { return $('#catalogTree').tree('getSelected'); }
    function getSameCatalog(node) {
        if ($('#catalogTree').tree('getParent', node.target) == null) return $('#catalogTree').tree('getRoots');
        else return $('#catalogTree').tree('getParent', node.target).children;
    }
</script>
@Html.Partial("~/Views/Shared/_TreeScriptsPartial.cshtml")

@Html.Import(Von.Web.Html.EImportSection.BodyTrailler, "HtmlCatalogInit",
    @<script>
        var von = VonGrid({
            app: "Content",
            keyName: "ID",
            fields: ["ID", "HtmlName", "Title", "Autor", "Src", "Linker", "Keyword", "Tags", "Summary"],
            displayFields: ["HtmlName", "Title", "Autor", "Src", "Status", "Publishedate"],
            onAddBtns: function (data) {
                von.addAction("", "Home", "HtmlContent/" + data.ID, "查看");
            }
        });
        $(function () {
            AjaxPostData('@Url.Ajax("admin/TreeOfHtmlCatalog")', { ID: 0 },
                function (result) {
                    $('#catalogTree').tree({
                        data: result,
                        onClick: LoadContentList
                    });
                });
        });
    </script>
)